import request from "@/utils/request";

// 注册
export const userRegisterApi = (registerData) => {
  // x-www-form-urlencoded这个形式的参数请求方式需借助URLSearchParams
  const params = new URLSearchParams()
  for (let key in registerData) {
    params.append(key, registerData[key])
  }

  return request.post('/user/register', params)
}

// 登录
export const userLoginApi = (loginData) => {
  // 参数多传不会导致报错，如loginData中会多一个rePassword
  const params = new URLSearchParams()
  for (let key in loginData) {
    params.append(key, loginData[key])
  }

  return request.post('/user/login', params)
}

// 获取用户所有资料
export const userInfoApi = () => request.get('/user/userInfo')

// 修改用户信息【username,nickname,email】
export const userUpdateApi = (userInfo) => request.put('/user/update',userInfo)

// 更新用户头像
export const userUpdateAvatarApi = (avatarUrl) => request.patch('/user/updateAvatar?avatarUrl='+avatarUrl)

// 更改密码
export const userUpdatePwdApi = (pwds)=>request.patch('/user/updatePwd',pwds)